import logging.handlers
import log
import datetime

"""
#####################
公共函数，
#####################
logger = logger
日志处理模块，分为时间file切割debug， 用户file:error
logger name='lhwms'
logger.setLever
handler name='handlerToFileAll'
handler class = logging.handlers.TimedRotatingFileHandler()
handler.setFormatter
handler.setLever
"""


def log_print(excepts=None, debug=None, info=None,
              waring=None, error=None, critical=None):
    """
   日志打印
    :param excepts:异常信息传值
    :param debug:
    :param info:
    :param waring:
    :param error:
    :param critical:
    :return: file
    """
    try:
        logger = log.logger
        # logger默认为WARNING,先日志对象级别，再管理器级别
        logger.setLevel(logging.INFO)
        # 对管理器输出格式化
        handlerToFileAll = log.handlerToFileAll
        handlerToFileAll.setFormatter(logging.Formatter(
            '%(asctime)s - %(levelname)s - %(filename)s[:%(lineno)d]'
            '- %(message)s'))

        # handlers添加到logger中，进行目的要求输出
        logger.addHandler(handlerToFileAll)

        if excepts is not None:
            logger.exception(excepts)  # 打印日志,error,tracback
        if debug is not None:
            logger.debug(debug)
        if info is not None:
            logger.info(info)
        if waring is not None:
            logger.warning(waring)
        if error is not None:
            logger.error(error)
        if critical is not None:
            logger.critical(critical)
    except:
        pass


def login_print(info):
    """用户登陆信息"""
    try:
        logger = log.logger
        logger.setLevel(logging.INFO)

        handlerToUserLogin = log.handlerToUserLogin
        # handlerToUserLogin.setLevel(logging.ERROR)
        handlerToUserLogin.setFormatter(logging.Formatter(
            '%(asctime)s - %(message)s'))

        logger.addHandler(handlerToUserLogin)
        logger.info(info)
    except:
        pass
